package com.example.studentcourse.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.studentcourse.common.Result;
import com.example.studentcourse.entity.StudentCourse;
import com.example.studentcourse.service.IStudentCourseService;
import com.example.studentcourse.vo.StudentCourseQueryVO;
import com.example.studentcourse.vo.StudentCourseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 选课记录管理接口
 */
@RestController
@RequestMapping("/student-course")
public class StudentCourseController {

    @Autowired
    private IStudentCourseService studentCourseService;

    /**
     * 分页条件查询选课记录
     * @param query 查询参数
     * @return 分页结果
     */
    @PostMapping("/list")
    public Result<Page<StudentCourseVO>> list(@RequestBody StudentCourseQueryVO query) {
        Page<StudentCourseVO> page = studentCourseService.pageVO(query);
        return Result.success(page);
    }

    /**
     * 学生选课
     */
    @PostMapping
    public Result<?> save(@RequestBody StudentCourse studentCourse) {
        studentCourseService.save(studentCourse);
        return Result.success(null);
    }

    /**
     * 修改成绩
     */
    @PutMapping
    public Result<?> update(@RequestBody StudentCourse studentCourse) {
        studentCourseService.updateById(studentCourse);
        return Result.success(null);
    }

    /**
     * 删除选课记录
     */
    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Long id) {
        studentCourseService.removeById(id);
        return Result.success(null);
    }

    /**
     * 批量删除选课记录
     */
    @DeleteMapping("/batch")
    public Result<?> deleteBatch(@RequestBody List<Long> ids) {
        studentCourseService.removeByIds(ids);
        return Result.success(null);
    }
} 